Toutes les variables graphiques ne se valent pas.
Ce quio est intéressant n’est pas toujours ce que l’on a au départ.
library(ggplot2)
ggplot(mpg)+geom_point(aes(x=cty,y=hwy,color=class))library(rjson)
library(dplyr)
?mpgmanufacturer.
model.
displ. engine displacement, in litres
m_cty = mpg %>% group_by(manufacturer) %>% summarize(mcty=mean(cty))
ggplot(data=m_cty)+
geom_bar(aes(x=manufacturer,y=mcty),stat = 'identity')+
scale_x_discrete("Manufacturer")+
scale_y_continuous("Miles / Gallon (City conditions)")m_cty_ordered = m_cty %>% arrange(desc(mcty)) %>%
mutate(manufacturer=factor(manufacturer,levels=manufacturer))
ggplot(data=m_cty_ordered)+
geom_bar(aes(x=manufacturer,y=mcty),stat = 'identity')+
scale_x_discrete("Manufacturer")+
scale_y_continuous("Miles / Gallon (City conditions)")ggplot(data=m_cty_ordered)+
geom_bar(aes(x=manufacturer,y=mcty),stat = 'identity')+
scale_x_discrete("Manufacturer")+
scale_y_continuous("Miles / Gallon (City conditions)")+
coord_flip()url="http://vlsstats.ifsttar.fr/data/temporalstats_NewYork.json"
# lecture des données
data=fromJSON(file=url)
# construction d'une liste de data.frame homogènes
tempstats.list=lapply(data,function(x){
data.frame(time=x$'_id',nbbikes=x$value$total_available_bikes)})
# concatenations des data.frame ?do.call
tempstats.df=do.call(rbind,tempstats.list)ggplot(data=tempstats.df,aes(x=time,y=nbbikes))+geom_point()ggplot(data=tempstats.df,aes(x=time,y=nbbikes))+geom_line()ggplot(data=tempstats.df,aes(x=time,y=nbbikes))+geom_line()ggplot(data=tempstats.df,aes(x=time,y=nbbikes))+geom_line()ggplot(data=tempstats.df,aes(x=time,y=nbbikes))+geom_line()ggplot(data=tempstats.df,aes(x=time,y=nbbikes))+geom_area()ggplot(data=tempstats.df,aes(x=time,y=max(nbbikes)-nbbikes))+
geom_area()# téléchargement et remise en forme des données
url = "http://vlsstats.ifsttar.fr/data/spatiotemporalstats_NewYork.json"
data=fromJSON(file=url)
extract = function(x){
data.frame(id=x$'_id',
time= x$download_date,
nbbikes = x$available_bikes )
}
st_tempstats.df=do.call(rbind,lapply(data,extract))
# selection de 3 stations
st_tempstats_sub.df = st_tempstats.df %>%
filter(id %in% c(397,398,3637,474,525,2000,401))ggplot(data=st_tempstats_sub.df)+
geom_line(aes(x=time,y=nbbikes,group=id,color=factor(id)),size=2)ggplot(data=st_tempstats_sub.df)+
geom_line(aes(x=time,y=nbbikes,group=id,color=factor(id)),size=2)+
facet_grid(id ~ .)mpg_su = mpg %>%
filter(class %in% c('compact','suv','pickup','minivan'))
ggplot(mpg_su)+geom_point(aes(x=cty,y=hwy,color=class))mpg_su = mpg %>%
filter(class %in% c('compact','suv','pickup','minivan'))
ggplot(mpg_su)+geom_point(aes(x=cty,y=hwy,shape=class))ggplot(mpg_su)+geom_point(aes(x=cty,y=hwy,color=class,size=displ))ggplot(mpg_su)+geom_point(aes(x=cty,y=hwy,color=class,size=displ))\[\textrm{Lie factor} = \frac{\textrm{visual effect size}}{\textrm{data effect size}}\]
Sachant que l’aire de la tranche “apple”" (en vert) est proportionelle à \(2.22\,cm^2\) et celle correspondant à rim (en bleue) est proportionelle à \(2.96\,cm^2\) calculer le lying factor ?
+geom_line()
aes(x=a,y=b,...)
ggplot(mpg)+
geom_point(aes(x=cty,y=hwy,color=manufacturer,shape=factor(cyl)))
ggplot(mpg,aes(x=cty,y=hwy,color=manufacturer,shape=factor(cyl)))+
geom_jitter()
ggplot(mpg,aes(x=cty,y=hwy,color=manufacturer))+geom_point()ggplot(mpg,aes(x=cty,y=hwy,color=manufacturer))+geom_jitter()ggplot(mpg,aes(x=cty,fill=manufacturer))+geom_histogram(binwidth=2)ggplot(mpg,aes(y=cty,x=manufacturer))+geom_violin()+geom_line()
aes(x=a,y=b,...)
scale_fill_brewer(palette=3,type="qual")
scale_x_continuous(limits=c(0,45),breaks=seq(0,45,2))
ggplot(mpg,aes(x=cty,y=hwy,color=manufacturer,shape=factor(cyl)))+
geom_jitter()+
scale_x_continuous(limits=c(0,45),breaks=seq(0,45,2))+geom_line()
aes(x=a,y=b,...)
scale_fill_brewer(palette=3,type="qual")
scale_x_continuous(limits=c(0,45),breaks=seq(0,45,2))
facet_grid(. ~ cyl)
ggplot(data=mpg,aes(x=hwy,y=cty,color=class))+
geom_point()+
facet_wrap(~year)+geom_line()
aes(x=a,y=b,...)
scale_fill_brewer(palette=3,type="qual")
scale_x_continuous(limits=c(0,45),breaks=seq(0,45,2))
stat_density2d()
ggplot(mpg,aes(y=cty,x=hwy))+
geom_point(color="blue")+stat_density2d()ggplot(mpg,aes(y=cty,x=hwy))+
geom_point(color="blue")+stat_smooth()library(hexbin)
ggplot(mpg,aes(y=cty,x=hwy))+
stat_binhex()Reprendre les échelles, légendes de cette figures
# téléchargement et remise en forme des données
url="http://vlsstats.ifsttar.fr/data/spatiotemporalstats_NewYork.json"
data=fromJSON(file=url)
extract = function(x){
data.frame(id=x$'_id',
time= x$download_date,
nbbikes = x$available_bikes )
}
st_tempstats.df=do.call(rbind,lapply(data,extract))
# selection de 3 stations
st_tempstats_sub.df = st_tempstats.df %>%
filter(id %in% c(397,398,3637,474,525,2000,401))
ggplot(data=st_tempstats_sub.df)+
geom_line(aes(x=time,y=nbbikes,group=id,color=factor(id)),size=2)+
facet_grid(id ~ .)Reprendre les échelles, légendes de cette figures
Reproduire ce graphique (Les données Iris sont déjà chargées)
Reproduire ce graphique (Les données mtcars sont déjà chargées) ! modifier le theme du graphique ?theme
Reproduire ce graphique